package com.baimawangzi.recovery.dao.impl;

import com.baimawangzi.recovery.bean.Integral;
import com.baimawangzi.recovery.dao.IntegralDao;
import com.baimawangzi.recovery.util.dbutil.BeanHandler;
import com.baimawangzi.recovery.util.dbutil.OnlyHandler;

import java.util.List;

public class IntegeralDaoImpl extends BaseDaoImpl<Integral>implements IntegralDao {
    public IntegeralDaoImpl() {
        clazz= Integral.class;
        init();
    }
    @Override
    public List<Integral> map(String sql, Object[] obj) {
        List<Integral> integrals = queryRunner.query(sql, new BeanHandler<Integral>(clazz), obj);
        return integrals;
    }
    @Override
    public List<Integral> findByLimit(int m, int n) {
        String sql="select id,username,integraltime,integral from t_user limit ?,?";
        Object[] object= {m, n};
        List<Integral> integrals = queryRunner.query(sql, new BeanHandler<Integral>(clazz), object);
        return integrals;
    }

    @Override
    public long getCount() {
        String sql="select count(*) totalSize from t_user where ?=?";
        Object[] object= {1, 1};
        List<Object> onlylist = queryRunner.query(sql,new OnlyHandler(),object);
        return (long) onlylist.get(0);
    }

    @Override
    public Integral findById(int id) {
        String sql="select id,username,integraltime,integral from t_user where id = ?";
        Object[] object= {id};
        Integral integral = queryRunner.query(sql, new BeanHandler<Integral>(clazz), object).get(0);

        return integral;
    }

    @Override
    public int update(Integral integral) {
        String sql="update t_user set integral=? where id=?";
        Object[] object= {integral.getIntegral(),integral.getId()};
        return queryRunner.update(sql,object);
    }
}
